```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Redis内存优化指南 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .hero-title {
            font-family: 'Noto Serif SC', serif;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
        }
        .step-icon {
            width: 48px;
            height: 48px;
            font-size: 20px;
        }
        .solution-card {
            border-left: 4px solid;
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(118, 75, 162, 0.2);
            z-index: -1;
            transition: height 0.3s ease;
        }
        .highlight:hover:after {
            height: 50%;
        }
        .fancy-quote {
            position: relative;
            padding-left: 2rem;
        }
        .fancy-quote:before {
            content: '"';
            position: absolute;
            left: 0;
            top: -1rem;
            font-family: 'Noto Serif SC', serif;
            font-size: 5rem;
            color: rgba(118, 75, 162, 0.1);
            line-height: 1;
        }
        .footer-link:hover {
            color: #667eea;
        }
        .mermaid {
            background-color: white;
            padding: 1.5rem;
            border-radius: 0.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 px-4 md:py-24">
        <div class="container mx-auto max-w-5xl text-center">
            <h1 class="hero-title text-4xl md:text-5xl lg:text-6xl font-bold leading-tight mb-4">
                Redis内存优化全景指南
            </h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8 max-w-3xl mx-auto">
                深入剖析内存溢出问题，提供专业级排查与优化方案
            </p>
            <div class="fancy-quote text-lg md:text-xl italic max-w-3xl mx-auto opacity-90">
                内存是Redis的生命线，优化内存使用不仅能提升性能，更能保障数据安全与系统稳定性。
            </div>
        </div>
    </section>

    <!-- Summary Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="bg-white rounded-xl shadow-md p-8 md:p-10">
                <div class="flex flex-col md:flex-row items-center">
                    <div class="md:w-1/3 mb-6 md:mb-0 md:pr-8">
                        <div class="bg-purple-100 text-purple-800 rounded-full w-20 h-20 flex items-center justify-center mx-auto">
                            <i class="fas fa-memory text-3xl"></i>
                        </div>
                    </div>
                    <div class="md:w-2/3">
                        <h2 class="text-2xl md:text-3xl font-bold mb-4 text-gray-800">Redis内存管理核心要义</h2>
                        <p class="text-gray-600 mb-4">
                            Redis作为高性能内存数据库，内存使用直接影响其稳定性。内存溢出(OutOfMemory)可能导致数据丢失、服务不可用等严重问题。本指南将系统性地介绍：
                        </p>
                        <ul class="grid grid-cols-1 md:grid-cols-2 gap-2 text-gray-600">
                            <li class="flex items-center"><i class="fas fa-check-circle text-purple-600 mr-2"></i> 内存问题排查步骤</li>
                            <li class="flex items-center"><i class="fas fa-check-circle text-purple-600 mr-2"></i> 专业解决方案</li>
                            <li class="flex items-center"><i class="fas fa-check-circle text-purple-600 mr-2"></i> 最佳实践建议</li>
                            <li class="flex items-center"><i class="fas fa-check-circle text-purple-600 mr-2"></i> 可视化分析</li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Visualization Section -->
    <section class="py-12 px-4 bg-gray-100">
        <div class="container mx-auto max-w-5xl">
            <h2 class="text-3xl font-bold text-center mb-12 text-gray-800">Redis内存问题全景分析</h2>
            <div class="mermaid">
                graph TD
                    A[Redis内存问题] --> B[内存配置不当]
                    A --> C[大数据对象]
                    A --> D[内存碎片]
                    A --> E[缓存管理不善]
                    A --> F[持久化策略]
                    
                    B --> B1[maxmemory设置不合理]
                    B --> B2[淘汰策略不匹配]
                    
                    C --> C1[键值过大]
                    C --> C2[数据结构选择不当]
                    
                    D --> D1[碎片率过高]
                    D --> D2[分配器效率低]
                    
                    E --> E1[过期时间设置不当]
                    E --> E2[淘汰机制不生效]
                    
                    F --> F1[RDB内存占用]
                    F --> F2[AOF内存占用]
                    
                    G[解决方案] --> H[优化配置]
                    G --> I[拆分大对象]
                    G --> J[减少碎片]
                    G --> K[监控预警]
                    G --> L[集群部署]
                    
                    H --> H1[合理设置maxmemory]
                    H --> H2[选择适当淘汰策略]
                    
                    I --> I1[数据分片]
                    I --> I2[使用高效结构]
                    
                    J --> J1[定期重启]
                    J --> J2[MEMORY PURGE]
                    
                    K --> K1[监控工具]
                    K --> K2[告警机制]
                    
                    L --> L1[Redis Cluster]
                    L --> L2[分片代理]
            </div>
        </div>
    </section>

    <!-- Problem Section -->
    <section class="py-16 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">Redis内存问题排查六步法</h2>
                <p class="text-gray-500 max-w-2xl mx-auto">系统性地诊断Redis内存问题的专业流程</p>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                <!-- Step 1 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-cog"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">1. 检查内存配置</h3>
                        <p class="text-gray-600">
                            使用 <span class="highlight font-mono">CONFIG GET maxmemory</span> 查看Redis内存限制设置，确保与实际需求匹配。检查 <span class="highlight font-mono">maxmemory-policy</span> 设置的淘汰策略是否合理。
                        </p>
                    </div>
                </div>
                
                <!-- Step 2 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-chart-bar"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">2. 分析内存使用</h3>
                        <p class="text-gray-600">
                            通过 <span class="highlight font-mono">INFO memory</span> 查看内存详情，关注 <span class="highlight">used_memory</span> 和 <span class="highlight">used_memory_rss</span> 差异。<span class="highlight font-mono">MEMORY STATS</span> 提供更详细统计信息。
                        </p>
                    </div>
                </div>
                
                <!-- Step 3 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-search"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">3. 识别大对象</h3>
                        <p class="text-gray-600">
                            使用 <span class="highlight font-mono">MEMORY USAGE &lt;key&gt;</span> 分析特定键内存占用。<span class="highlight font-mono">SCAN</span> 遍历所有键，结合 <span class="highlight font-mono">MEMORY USAGE</span> 找出内存消耗最大的对象。
                        </p>
                    </div>
                </div>
                
                <!-- Step 4 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-puzzle-piece"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">4. 查看内存碎片</h3>
                        <p class="text-gray-600">
                            通过 <span class="highlight">mem_fragmentation_ratio</span> 检查碎片率。高于1.5表示较严重碎片化，可能引发内存溢出，即使 <span class="highlight">used_memory</span> 未超限。
                        </p>
                    </div>
                </div>
                
                <!-- Step 5 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-clock"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">5. 监控缓存数据</h3>
                        <p class="text-gray-600">
                            使用 <span class="highlight font-mono">TTL &lt;key&gt;</span> 检查过期时间。确保缓存数据合理设置过期，避免无效数据堆积。检查淘汰策略是否生效。
                        </p>
                    </div>
                </div>
                
                <!-- Step 6 -->
                <div class="card bg-white rounded-xl overflow-hidden">
                    <div class="p-6">
                        <div class="step-icon bg-purple-100 text-purple-800 rounded-full flex items-center justify-center mb-4 mx-auto">
                            <i class="fas fa-save"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-3 text-gray-800">6. 检查持久化策略</h3>
                        <p class="text-gray-600">
                            检查RDB快照和AOF日志的生成频率及内存占用。过度持久化可能消耗大量内存，尤其在数据量大时。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Solution Section -->
    <section class="py-16 px-4 bg-gray-50">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">Redis内存优化专业解决方案</h2>
                <p class="text-gray-500 max-w-2xl mx-auto">从配置调整到架构升级的全面优化方案</p>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <!-- Solution 1 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-purple-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-sliders-h text-purple-500 mr-3"></i> 优化内存配置
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>根据业务需求调整 <span class="highlight font-mono">maxmemory</span>，留出20%缓冲空间</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>缓存场景推荐 <span class="highlight font-mono">allkeys-lru</span> 或 <span class="highlight font-mono">volatile-lru</span> 淘汰策略</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2"></i>
                            <span>使用 <span class="highlight font-mono">lazyfree-lazy-eviction</span> 减少大键删除阻塞</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Solution 2 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-blue-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-cut text-blue-500 mr-3"></i> 清理大数据对象
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>将大对象拆分为多个小对象 (<span class="highlight">分片</span>)</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>使用更高效的数据结构，如用 <span class="highlight font-mono">ziplist</span> 替代普通list</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2"></i>
                            <span>定期扫描并清理长期未访问的大键</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Solution 3 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-green-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-broom text-green-500 mr-3"></i> 降低内存碎片
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>定期重启Redis服务（低峰期）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>使用 <span class="highlight font-mono">MEMORY PURGE</span> 主动释放碎片</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2"></i>
                            <span>调整jemalloc配置优化内存分配</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Solution 4 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-yellow-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-clock text-yellow-500 mr-3"></i> 优化过期数据
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                            <span>为缓存数据设置合理的TTL</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                            <span>启用 <span class="highlight font-mono">activedefrag</span> 自动碎片整理</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-yellow-500 mt-1 mr-2"></i>
                            <span>监控过期键比例，避免大量键同时过期</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Solution 5 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-red-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-chart-line text-red-500 mr-3"></i> 监控和预警
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-red-500 mt-1 mr-2"></i>
                            <span>部署 <span class="highlight">Prometheus+Grafana</span> 监控内存使用</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-red-500 mt-1 mr-2"></i>
                            <span>设置内存使用率超过80%自动告警</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-red-500 mt-1 mr-2"></i>
                            <span>监控碎片率和键空间变化趋势</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Solution 6 -->
                <div class="solution-card bg-white rounded-lg p-6 border-l-4 border-indigo-500">
                    <h3 class="text-xl font-bold mb-3 text-gray-800 flex items-center">
                        <i class="fas fa-server text-indigo-500 mr-3"></i> 架构升级
                    </h3>
                    <ul class="text-gray-600 space-y-2">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>升级服务器内存容量</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>部署 <span class="highlight">Redis Cluster</span> 集群模式</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mt-1 mr-2"></i>
                            <span>使用 <span class="highlight">Twemproxy</span> 或 <span class="highlight">Codis</span> 实现分片代理</span>
                        </li>
                    </ul>
                </div>
            </div>
        </div>
    </section>

    <!-- Command Cheatsheet -->
    <section class="py-16 px-4 bg-white">
        <div class="container mx-auto max-w-5xl">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">Redis内存管理命令速查表</h2>
                <p class="text-gray-500 max-w-2xl mx-auto">关键命令一览，助您快速诊断与优化</p>
            </div>
            
            <div class="overflow-x-auto">
                <table class="min-w-full bg-white rounded-lg overflow-hidden">
                    <thead class="bg-gray-100">
                        <tr>
                            <th class="py-3 px-4 text-left text-gray-700 font-semibold">命令</th>
                            <th class="py-3 px-4 text-left text-gray-700 font-semibold">功能描述</th>
                            <th class="py-3 px-4 text-left text-gray-700 font-semibold">关键指标</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">INFO memory</td>
                            <td class="py-3 px-4">查看内存使用概况</td>
                            <td class="py-3 px-4">used_memory, used_memory_rss, mem_fragmentation_ratio</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">MEMORY STATS</td>
                            <td class="py-3 px-4">详细内存统计信息</td>
                            <td class="py-3 px-4">allocator指标, 数据集大小, 缓存命中率</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">MEMORY USAGE key</td>
                            <td class="py-3 px-4">查看指定键内存占用</td>
                            <td class="py-3 px-4">字节大小(包括开销)</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">MEMORY PURGE</td>
                            <td class="py-3 px-4">主动释放内存碎片</td>
                            <td class="py-3 px-4">(无返回指标)</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">CONFIG GET maxmemory</td>
                            <td class="py-3 px-4">查看内存限制配置</td>
                            <td class="py-3 px-4">maxmemory值(字节)</td>
                        </tr>
                        <tr class="hover:bg-gray-50">
                            <td class="py-3 px-4 font-mono text-purple-600">SCAN cursor</td>
                            <td class="py-3 px-4">遍历数据库键</td>
                            <td class="py-3 px-4">结合MEMORY USAGE找出大键</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-4">
        <div class="container mx-auto max-w-5xl">
            <div class="flex flex-col items-center text-center">
                <div class="text-2xl font-bold mb-2">技术小馆</div>
                <p class="text-gray-400 mb-6">专业的技术知识与实践指南</p>
                <a href="http://www.yuque.com/jtostring" class="footer-link text-gray-300 hover:text-white transition-colors">
                    <i class="fas fa-external-link-alt mr-2"></i>http://www.yuque.com/jtostring
                </a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```